<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="index.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="favicon.ico">
<link rel="Shortcut Icon" href="favicon.ico" />

<title>主页</title>
<meta name="keywords" content="耶回收">
<meta name="description" content="耶回收">

</head>
<body>
	<!--_表格--开始-->
	<section class="Hui-article-box" style="overflow: auto"> <nav
		class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
	新闻管理 <span class="c-gray en">&gt;</span> 新闻信息管理 <span class="c-gray en">&gt;</span>
	新闻添加 </nav>

	<div class="page-container">
		<form action="newsadd" method="post" class="form form-horizontal"
			id="form-back-add">
			<div class="row cl" style="margin-top: 50px">
				<label class="form-label col-xs-4 col-sm-3">新闻主题：</label>
				<div class="formControls col-xs-8 col-sm-6">
					<input type="text" class="input-text"
						data-msg-required="新闻主题不能为空" data-rule-required="true" value="" placeholder="" id="" name="title">
				</div>
			</div>

			<div class="row cl" style="margin-top: 50px">
				<label class="form-label col-xs-4 col-sm-3">新闻主题描述：</label>
				<div class="formControls col-xs-8 col-sm-6">
					<input type="text" class="input-text"
						data-msg-required="主题描述不能为空" data-rule-required="true" value="" placeholder="" id="" name="descrip">
				</div>
			</div>

			<div class="row cl" style="margin-top: 50px">
				<label class="form-label col-xs-4 col-sm-3">新闻链接：</label>
				<div class="formControls col-xs-8 col-sm-6">
					<input type="text" class="input-text"
						data-msg-required="新闻链接不能为空" data-rule-required="true" data-msg-url="链接格式不正确" url="true" value="" placeholder="" id="" name="link">
				</div>
			</div>
			
			<div class="row cl" style="margin-top: 50px">
				<label class="form-label col-xs-4 col-sm-3">整机类型：</label>
				<div class="formControls col-xs-8 col-sm-6">
					<select class="input-text" name="status">
						<option value="1">主新闻</option>
						<option value="2">次新闻</option>
					</select>
				</div>
			</div>

			<div class="row cl" style="margin-top: 50px">
				<label class="form-label col-xs-4 col-sm-3">新闻图片：</label>
				<div class="formControls col-xs-8 col-sm-6">
					<input type="hidden" id="image" value="" name="image"> 
					<input type="file" class=""  data-msg-required="新闻图片不能为空" data-rule-required="true" value="" id="img">
					<span id="showimg"></span> <input type="button"
						class="btn btn-primary radius"
						onclick="imgupload()" value="添加">
				</div>
			</div>

			<div class="row cl" style="margin-top: 50px">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<button class="btn btn-primary radius" type="submit">
						<i class="Hui-iconfont">&#xe632;</i>添加新闻
					</button>
				</div>
			</div>

		</form>
	</div>

	</section>

</body>
<script type="text/javascript"
	src="lib/webuploader/0.1.5/webuploader.min.js"></script>
<script src="<%=basePath%>lib/jquery.validation/1.14.0/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
	function imgupload() {
		var animateimg = $("#img").val(); //获取上传的图片名 带//
		var imgarr = animateimg.split('\\'); //分割 
		var myimg = imgarr[imgarr.length - 1]; //去掉 // 获取图片名 
		var houzui = myimg.lastIndexOf('.'); //获取 . 出现的位置
		var ext = myimg.substring(houzui, myimg.length).toUpperCase(); //切割 . 获取文件后缀 
		var file = $("#img").get(0).files[0]; //获取上传的文件
		var form = new FormData();
		form.append("ext", ext);
		form.append("file", file);
		if (ext != '.PNG' && ext != '.GIF' && ext != '.JPG' && ext != '.JPEG'
				&& ext != '.BMP') {
			parent.layer.msg('文件类型错误,请上传图片类型');
			return false;
		} else {
			// var data = new FormData($('#form1')[0]);
			$
					.ajax({
						url : "imgupdate",
						type : 'POST',
						data : form,
						dataType : 'JSON',
						processData : false, // 注意：让jQuery不要处理数据
						contentType : false, // 注意：让jQuery不要设置contentType
						success : function(ret) {
							$("#image").val(ret.filepath);
							$("#showimg")
									.html(
											'<img src="'+ret.filepath+'" height="100px" width="100px" style="margin-right: 100px;margin-top: 50px">');
							layer.msg('上传成功');
							/* if(ret=="1"){  
							    var result = '';  
							    var result1 = '';  
							    // $("#show").attr('value',+ ret['f'] +);  
							    result += '<img src="' + '__ROAD__' + ret['f']  + '" width="100">';  
							    result1 += '<input value="' + ret['f']  + '" name="user_headimg" style="display:none;">';  
							    $('#result').html(result);  
							    $('#show').html(result1);  
							    layer.msg('上传成功');  
							}else{    
							    layer.msg('上传失败');  
							} */
						}
					});
		}

	}
	
	
	//表单验证
	$(function(){
		 
		 $("#form-back-add").validate( {
			         //做完表单验证后的  ajax后台数据验证 如果不满足条件 则禁止表单的提交
				    /* submitHandler: function(form){
					
				     return checkimage();
				     //发出ajax请求 根据回调函数的返回值 来判断checkBackitemExsit()的返回值；
				    
				    } */
		 
			 
		 }); 
	 });

</script>
</html>